// Copyright (C) ZHENG Zhong <heavyzheng nospam-at gmail D0T com>
//
// $Id: test_resource.cpp 316 2009-01-08 18:01:10Z heavyzheng $
//

#include <zzheng/test_resource.hpp>
#include <zzheng/test_logging.hpp>

#include <zzheng/utility/boost_filesystem.hpp>
#include <zzheng/utility/sys_env.hpp>

#include <string>

namespace zzheng {
namespace test {

    std::string get_resource_dir() {
        std::string dirname = zzheng::sys::expand_sys_var("${zzheng.project.root}/test/resource");
        boost::filesystem::path dir = zzheng::make_path(dirname);
        if (!boost::filesystem::exists(dir) || !boost::filesystem::is_directory(dir)) {
            std::string errmsg = "Invalid test resource directory: " + dir.string();
            error(errmsg);
            throw resource_error(errmsg.c_str());
        }
        return dir.string();
    }

    std::string get_output_dir() {
        std::string dirname = zzheng::sys::expand_sys_var("${zzheng.project.root}/test/tmp");
        boost::filesystem::path dir = zzheng::make_path(dirname);
        if (!boost::filesystem::exists(dir)) {
            boost::filesystem::create_directory(dir);
        }
        if (!boost::filesystem::exists(dir) || !boost::filesystem::is_directory(dir)) {
            std::string errmsg = "Invalid test output directory: " + dir.string();
            error(errmsg);
            throw resource_error(errmsg.c_str());
        }
        return dir.string();
    }

} // namespace zzheng::test
} // namespace zzheng



